<template>
	<view>
		<view>
			<view class="seek-box">
				<image class="seek-img" src="../../static/index/search.png"></image>
				<input type="text" class="z-font-26" placeholder="搜索城市" />
			</view>
			<block v-if="realAddress">
				<view class="title z-padding-32">当前城市</view>
				<view class="cur-city z-margin-l-32 z-font-26" @click="selectCity(realAddress.city)">
					<image class="city-img z-margin-r-8" src="../../static/index/locations.png"></image>
					{{ realAddress.city }}
				</view>
			</block>

			<view class="title z-padding-t-48 z-padding-lr-32">热门城市</view>
			<view class="hot-box z-padding-lr-32">
				<view class="each-hot z-text-c z-margin-t-24 z-margin-r-24 z-font-26" v-for="(item,index) in list" @click="selectCity(item.city)">{{ item.city }}</view>
			</view>

			<!-- <van-index-bar>
				<view v-for="{{city}}">
					<van-index-anchor index="{{item.anchor}}" />
					<van-cell v-for="{{item.area}}" v-for-item="i" title="{{i.name}}" bind:click="selectCity" data-city="{{i.name}}" />
				</view>
			</van-index-bar> -->

			<!-- <view v-for="{{city}}" v-key="indexs">
		    <view>{{item.idx}}</view>
		    <view v-for="{{item.cities}}" v-key="idxs" v-for-item="i">{{i.city_name}}</view>
		  </view> -->
		</view>
	</view>
</template>

<script>
import http from '../../utils/http';

export default {
	data() {
		return {
			city: [],
			list: [],
			realAddress:uni.getStorageSync('address'),
		};
	},
	methods: {
		selectCity(e) {
			let city = e;
			const eventChannel = this.getOpenerEventChannel();
			eventChannel.emit('selectCity', city);
			this.util.back();
		},
		getList() {
			http.get('user/getarea').then((res) => {
				let city = [];
				for (let i = 65; i <= 90; i++) {
					let arr = res.data.areaList.filter((value) => {
						return value.pinyin.substr(0, 1).toUpperCase() == String.fromCharCode(i);
					});
					city.push({
						anchor: String.fromCharCode(i),
						area: arr
					});
				}
				this.list = res.data.openCity,
				this.city = city
			});
		},
	},
	onLoad(options) {
		this.getList();
	}
};
</script>

<style>
page {
	background-color: #ffffff;
}
.seek-box {
	width: 686rpx;
	height: 70rpx;
	background: #f5f7f9;
	border-radius: 44rpx 44rpx 44rpx 44rpx;
	opacity: 1;
	margin: auto;
	display: flex;
	align-items: center;
	margin-top: 42rpx;
}
.seek-img {
	width: 24rpx;
	height: 24rpx;
	margin: 0 18rpx 0 34rpx;
}

.title {
	font-size: 30rpx;
	font-weight: bold;
	color: #1c274c;
}

.cur-city {
	width: 200rpx;
	box-sizing: border-box;
	padding: 16rpx 32rpx;
	background: #f5f7f9;
	border-radius: 8rpx 8rpx 8rpx 8rpx;
	opacity: 1;
	display: flex;
	justify-content: center;
	align-items: center;
}
.city-img {
	width: 26rpx;
	height: 26rpx;
	margin-right: 10rpx;
}
.hot-box {
	display: flex;
	align-items: center;
	flex-wrap: wrap;
}
.each-hot {
	width: 200rpx;
	height: 68rpx;
	background: #f5f7f9;
	border-radius: 8rpx 8rpx 8rpx 8rpx;
	opacity: 1;
	line-height: 68rpx;
}
</style>
